#!/usr/bin/perl
#
# newdb.pl 
#
# creates a new sqlite database for Hijinx OSPOS
#

use lib qw( /home/dan/usr/local/lib/perl5/site_perl/5.8.7/
 /home/dan/usr/local/lib/perl5/site_perl/5.8.5/
/home/dan/cpro.hijinxcomics.com/hijinx);
use DBI;
my $file = shift || die "usage: newdb.pl <sqlite.db>";
my $sqlite = DBI->connect( "dbi:SQLite:dbname=$file", "", "" ) or die "can't connect!" ;
my $limit = shift || 10;

$sqlite->do( "create table if not exists passwd(id,login,pass,perm_level,fname,lname,email,opt_in) ") || die "can't create passwd";
$sqlite->do("create table if not exists sessions(id integer primary key )") || die "can't create table sessions\n";
$sqlite->do("insert into passwd values ('1','dan','S8DVaKe1VGInM','2','Dan','Shahin','dan@hijinxcomics.com', '1')") || die "can't insert dan";

$sqlite->do( "create table if not exists customers(id integer primary key, fname, lname, email, add1, add2, zip, phone, created, frozen, old_id, bc_id, credit) ") || die "can't create customers";

$sqlite->do( "create table if not exists products(id integer primary key, name, price, store_price, online_price, barcode1 , barcode2 , category, series, family, issue, volume, dcd unique, isbn10 unique, isbn13 ) ") || die "can't create products";

$sqlite->do( "create table if not exists previews(item_code primary key, stock_code, parent_code, replacement_code, full_title, main_desc, variant_desc, series_code, issue_no, issue_seq_no, volume_tag, max_issue, price, supplier, upc_no, isbn, ean, unit_per_item, item_per_box, box_per_case, discount_code, po_reo_increment, print_date, foc, ship_date, srp, category, genre, brand_code, mature, adult, oa, caut1, caut2, caut3, resol, note_price, order_form_notes, page_number, writer, artist, cover_artist, content_desc, batchno, linenum) ") || die "can't create passwd";

$sqlite->do("create table if not exists invoices(id integer primary key,invoice_id, units_shipped, item_code, item_description, retail_price, unit_price, invoice_amount, category, order_type, processed_as, order_number, upc, isbn,ean,po_number,allocated, account_num, date )") || die "can't create table invoices\n";


$sqlite->do("create table if not exists notes(id integer primary key )") || die "can't create table notes\n";
$sqlite->do("create table if not exists series(id integer primary key )") || die "can't create table series\n";
$sqlite->do("create table if not exists creators(id integer primary key )") || die "can't create table creators\n";
$sqlite->do("create table if not exists tags(id integer primary key )") || die "can't create table tags\n";
$sqlite->do("create table if not exists orders(id integer primary key )") || die "can't create table orders\n";
$sqlite->do("create table if not exists received(id integer primary key )") || die "can't create table received\n";
$sqlite->do("create table if not exists sales(id integer primary key )") || die "can't create table sales\n";
